﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class StrategicPlan_ViewQuarterPlan : System.Web.UI.Page
{
    Model.UserInfo objUserInfo = new Model.UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDrp();
            Bindgdv();
        }
        if (objUserInfo.UserName != "admin")
        {
            this.btnDel0.Visible = false;
            this.btnModify.Visible = false;
        }
        else
        {
            this.btnDel0.Visible = true;
            this.btnModify.Visible = true;
        }
    }



    void BindDrp()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsInt("StrategicPlanId");
        DataTable dt_QuarterPlan = new BLL.QuarterPlanofManager().get(BLL.QuarterPlanofManager.field.StrategicPlanId.ToString(), _value);
        string ids = string.Empty;

        foreach (DataRow dr in dt_QuarterPlan.Rows)
        {
            ids += "" + dr["QuarterDate"].ToString() + ",";
        }
        if (ids.Length > 1)
        {
            ids = ids.Substring(0, ids.Length - 1);
        }

        _value = new object[1];
        _value[0] = ids;
        DataTable _quarter = new BLL.QuarterDateManager().GetQuarterDateByIds(_value);
        if (_quarter.Rows.Count != 0)
        {
            this.drpQuarterDate.DataSource = _quarter;
            this.drpQuarterDate.DataTextField = "QuarterName";
            this.drpQuarterDate.DataValueField = "Quarter_Id";
            this.drpQuarterDate.DataBind();
            this.drpQuarterDate.SelectedValue = Utility.HttpHelp.getParamsString("Quarter");
            this.drpQuarterDate.Items.Insert(0, new ListItem("全部","0"));
        }
        else
        {
            ListItem li = new ListItem("无年周期", "0");
            this.drpQuarterDate.Items.Clear();
            this.drpQuarterDate.Items.Add(li);
        }
    }


    void Bindgdv()
    {
        object[] _value = new object[3];
        _value[0] = Convert.ToInt32(this.drpQuarterDate.SelectedValue);

        _value[1] = Utility.HttpHelp.getParamsString("Department").ToString();
        _value[2] = Utility.HttpHelp.getParamsInt("StrategicPlanId");
        DataTable _quarterPlan = new BLL.QuarterPlanofManager().getStrategicPlanResolve(_value);
        this.gdvTotalPlan.DataSource = _quarterPlan;
        this.gdvTotalPlan.DataBind();
    }

    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void drpQuarter_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bindgdv();
    }


    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int QuarterPlanId = 0;
        for (int i = 0; i < this.gdvTotalPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvTotalPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                QuarterPlanId = Convert.ToInt32(this.gdvTotalPlan.DataKeys[i]["QuarterPlanId"].ToString());
                object[] _value = new object[1];
                _value[0] = QuarterPlanId;
                int val = new BLL.QuarterPlanofManager().del(BLL.QuarterPlanofManager.field.QuarterPlanId.ToString(), _value);
            }
        }

        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
        }
        Bindgdv();
    }

    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int QuarterPlanId = 0;
        for (int i = 0; i < this.gdvTotalPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvTotalPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                QuarterPlanId = Convert.ToInt32(this.gdvTotalPlan.DataKeys[i]["QuarterPlanId"].ToString());
            }
        }
        if (_count == 1)
        {
            string _url = "/QuarterPlan/ModifyQuarterPlan.aspx?_quarterPlanId=" + QuarterPlanId + "&Department=" + Utility.HttpHelp.getParamsString("Department") + "&url=/StrategicPlan/ViewQuarterPlan.aspx&_quarterDate=" + this.drpQuarterDate.SelectedValue + "&StrategicPlanId=" + Utility.HttpHelp.getParamsString("StrategicPlanId");
            Page.RegisterStartupScript("windowsopen1", "<script language=javascript>window.open('" + _url + "','newwindow','height=200px,width=1000px,top=100,left=100,toolbar=no,menubar=no,fullscreen=0,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
        else
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
        }
    }
}